/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmPrincipal.java
 *
 * Created on 13-ene-2010, 12:30:40
 */

package prova;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 *
 * @author ramon
 */
public class frmPrincipal extends javax.swing.JFrame {

    // Obtenció de la data actual del sistema

    Calendar c = GregorianCalendar.getInstance();

    int dia = c.get(Calendar.DAY_OF_MONTH);
    int mes = c.get(Calendar.MONTH)+1;
    int any = c.get(Calendar.YEAR);
    int dia_setmana = c.get(Calendar.DAY_OF_WEEK)-1;

    // Instancia d'un objecte per afegir alumnes

    afegirAlumnes af = new afegirAlumnes();

    /** Creates new form frmPrincipal */
    public frmPrincipal() {
        initComponents();
        // Visualitzo l'any actual en la caixa de text del curs
        jTextField4.setText(String.valueOf(any));

        // Comprovació del dia de la setmana en que ens trobem per deshabilitar el botó d'alta
        if (dia_setmana==5) {
            jButton1.setEnabled(false);
        }
    }

    // Funció per obtenir el curs que realitzarà l'alumne en funció del dia de la setmana en que ens trobem
    // Retorna un String amb el nom del curs

    public String obtenirCurs(){

        switch (dia_setmana){
            case 1: return "CFGS";
            case 2: return "BATXILLERAT";
            case 3: return "COU";
            case 4: return "CFGM";
            default:return "";
        }

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Formulari d'altes d'alumnes");
        setResizable(false);
        getContentPane().setLayout(new java.awt.BorderLayout(0, 4));

        jPanel1.setPreferredSize(new java.awt.Dimension(400, 65));
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 1, 15));

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 1, 26)); // NOI18N
        jLabel5.setText("ALUMNE");
        jPanel1.add(jLabel5);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

        jPanel2.setPreferredSize(new java.awt.Dimension(400, 85));

        jButton1.setText("Alta");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(163, 163, 163)
                .addComponent(jButton1)
                .addContainerGap(200, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jButton1)
                .addContainerGap(18, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_END);

        jPanel3.setLayout(new java.awt.BorderLayout(0, 12));

        jPanel4.setPreferredSize(new java.awt.Dimension(75, 150));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 75, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 184, Short.MAX_VALUE)
        );

        jPanel3.add(jPanel4, java.awt.BorderLayout.LINE_END);

        jPanel5.setPreferredSize(new java.awt.Dimension(75, 150));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 75, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 184, Short.MAX_VALUE)
        );

        jPanel3.add(jPanel5, java.awt.BorderLayout.LINE_START);

        jPanel6.setLayout(new java.awt.GridLayout(4, 2, 0, 26));

        jLabel1.setText("NOM");
        jPanel6.add(jLabel1);
        jPanel6.add(jTextField1);

        jLabel2.setText("COGNOMS");
        jPanel6.add(jLabel2);
        jPanel6.add(jTextField2);

        jLabel3.setText("DATA NAIXEMENT");
        jPanel6.add(jLabel3);

        jTextField3.setText("dd/mm/aaaa");
        jPanel6.add(jTextField3);

        jLabel4.setText("CURS");
        jPanel6.add(jLabel4);
        jPanel6.add(jTextField4);

        jPanel3.add(jPanel6, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Botó per afegir un alumne
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        // Construeixo un nou alumne

        alumne a = new alumne(jTextField1.getText(),jTextField2.getText(),jTextField3.getText(),jTextField4.getText(),obtenirCurs());

        // Afegeixo el nou alumne al vector d'alumnes

        af.addAlumne(a);

        // Visualitzo tot els alumnes
        recorrerMatriu();

        jTextField1.setText("");jTextField2.setText("");jTextField3.setText("dd/mm/aaaa"); 
        


    }//GEN-LAST:event_jButton1ActionPerformed

    // Visualitzo el contingut de la matriu d'alumnes

    public void recorrerMatriu(){
        Iterator iterator = af.iterator();
        while(iterator.hasNext()){
              alumne al = (alumne) iterator.next();
              System.out.println(al.getNom() +" "+  al.getCognoms()+ " " + al.getDataNaixement()+" CURS:"+  al.getCurs() + " ESTUDIS:" +al.getEstudis());
        }

    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmPrincipal().setVisible(true);
              
            }
        });


    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration//GEN-END:variables

}
